<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>浅拷贝</h2>
</body>
<script>
    //1.对象浅拷贝
    let obj = {
        name: 'alice',
        age: 20,
        address:{
            ad1:'地址1',
            ad2:'地址2',
        }
    }

    //对象之间的赋值，本质上是赋的地址,地址也称引用
    // let obj2 = obj;
    //let obj2 = Object.assign(obj)
    let obj2 = {...obj}  

   obj.name = '张三丰'
   obj.address.ad1='北京'

    //obj3创建一个新对象
    let obj3 = {
        name: 'alice',
        age: 20
    }

    // console.log('obj:', obj)
    // console.log('obj2:', obj2)
    // console.log('obj3:', obj3)

   // console.log('1:', obj === obj2) // true,false  //true
   // console.log('2:', obj === obj3) // true,false  ??

  //2.数组浅拷贝
  let arr=[11,22,33,'hello','vue',['aaa','bbb']]

 // let arr2=arr;

  // let arr2=arr.concat()
  // let arr2=arr.slice()
  let arr2=[...arr]


   arr.push('gogogog')
   arr[5].push('ok')

   console.log('arr:',arr)
   console.log('arr2:',arr2)

   



</script>

</html>